//
//  WBTitleBtn.swift
//  ZWWEIBO
//
//  Created by xzw on 2018/4/8.
//  Copyright © 2018年 xzw. All rights reserved.
//

import UIKit

class WBTitleBtn: UIButton {

    init(title:String?)
    {
       super.init(frame: CGRect())
        
        if title == nil {
            setTitle("首页", for: .normal)
        }else
        {
            setTitle(title! + " ", for: .normal)
        }
    
       setTitleColor(UIColor.darkGray, for: .normal)
       titleLabel?.font = UIFont.boldSystemFont(ofSize: 17)
    
        //设置图片
       setImage( UIImage(named: "navigationbar_arrow_down"), for: .normal)
       setImage( UIImage(named: "navigationbar_arrow_up"), for: .selected)
        
       //设置大小自适应
        sizeToFit()
    }
    
    //调整按钮位置
    override func layoutSubviews() {
        super.layoutSubviews()
        
        guard let imageView = imageView,let titleLabel = titleLabel else {
            return
        }
        
        print("\(imageView)---\(titleLabel)")
        
        titleLabel.frame = CGRect(x: 0, y: titleLabel.frame.origin.y, width: titleLabel.bounds.width, height: titleLabel.bounds.height)
        imageView.frame = CGRect(x: titleLabel.bounds.width, y: imageView.frame.origin.y, width: imageView.bounds.width, height: imageView.bounds.height)
        
    }
   
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
